<?php
if (!defined('CMS_SYSTEM')) die();
include_once("Cart.class.php");
global $db,$Default_Temp, $time, $currentlang,$prefix;
/*
 * phan lay ra thong tin nguoi dat hang
 * Le duc vien
 */
$name = $escape_mysql_string($_POST['person']);
$address = $escape_mysql_string($_POST['address']);
$phone = $escape_mysql_string($_POST['phone']);
$email = $escape_mysql_string($_POST['email']);
$message = $escape_mysql_string($_POST['content']);

$cart = new Cart(CART_SESS);
$newCart = $cart->getData();
$orderList = '';
foreach ($newCart as $productId => $productDetail) $orderList .= "{$productDetail['count']}x$productId,";
$orderList = substr($orderList, 0, strlen($orderList) - 1);

$cart->reset();
$sql="INSERT INTO {$prefix}_products_order (fullname, mail, phone, address, info, orderList, orderTime, status) VALUES ('$name', '$email', '$phone', '$address', '$message', '$orderList', NOW(), 0)";
$db->sql_query($sql);
include_once("templates/".$Default_Temp."/header.php");
		  include_once("templates/".$Default_Temp."/banner.php");
		  include_once("templates/".$Default_Temp."/menu.php");
		  /*
		   * Phan loc ra tat ca san pham
		   * Le duc vien
		   */
		 echo "<div id=\"wrapper\">";
			 echo "<div class=\"content fix\">";
			     //Noi dung phan loc tat ca san pham
			     echo "<div class=\"w720 fl\">";
			       echo "<div class=\"common\">";
			            echo "<div class=\"title\">";
						 echo "<h1 class=\"text\"><span>"._CART_ORDER_INFO."</span></h1>";
			    		echo "</div>";
					    echo "<div class=\"wrap fix\">";
					         echo "<div class=\"contact\">";
					              echo "<fieldset>";
										echo "<legend>"._CART_ORDER_INFO."</legend>";
										echo "<ul>";
										if ($db->sql_affectedrows($sql) >= 0) {
											foreach ($newCart as $productId => $productDetail) {
												$db->sql_query("UPDATE {$prefix}_products SET buyCount=buyCount+{$productDetail['count']} WHERE id=$productId");
											}
											echo "<li>";
												echo "<center>"._PRODUCT_CHECKED_OUT."</center>";
											echo "</li>";
										}else{
											echo "<li>";
												echo "<center>"._PRODUCT_ERROR_CHECKING_OUT."</center>";
											echo "</li>";
										}
										echo "</ul>";
							 	echo "</fieldset>";
					         echo "</div>";
					    echo "</div>";
			       echo "</div>";
			     echo "</div>";
			     include_once("templates/".$Default_Temp."/rightbody.php");
			 echo "</div>";
			 themeSlideShow(8);
			 themeFooter();
		 echo "</div>";
		 /*
		  * Ket thuc phan san pham
		  * 
		  */
		echo "<meta http-equiv=\"refresh\" content=\"5;url=index.php\">";    
		include_once("templates/".$Default_Temp."/footer.php");
?>